package com.gyt.manager.job;

import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob;
import com.gyt.manager.common.annotation.ElasticSimpleJob;
import com.gyt.manager.common.component.EnvComponent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * @author gyt created on 2021/5/16 16:54
 **/
@ElasticSimpleJob(cron = "0 */20 * * * ?", jobName = "myTestJob")
@Component
public class MyTestJob implements SimpleJob{
    private static final Logger LOGGER = LoggerFactory.getLogger(MyTestJob.class);

    @Override
    public void execute(ShardingContext shardingContext) {
        LOGGER.info("MyTestJob execute start ...");
        try {
            if (EnvComponent.isDev()) {
                return;
            }
            switch (shardingContext.getShardingItem()) {
                case 0: {
                    System.out.println("MyTestJob - 0");
                    break;
                }
                case 1: {
                    System.out.println("MyTestJob - 1");
                    break;
                }
                case 2: {
                    System.out.println("MyTestJob - 2");
                    break;
                }
                default: {
                    System.out.println("MyTestJob - default");
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            LOGGER.info("MyTestJob execute end ...");
        }
    }
}
